﻿using System;
using System.IO;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Navigation;

namespace LEDControl
{
	public partial class SingleLED
	{
        #region Private Members
        String _Value;
        Boolean _DecimalOn = false;

        #endregion

		public SingleLED()
		{
			this.InitializeComponent();

			// Insert code required on object creation below this point.
		}

        #region Public Accessors

        public String Value
        {
            get
            {
                return _Value;
            }
            set
            {
                _Value = value;
                UpdateDisplay();
            }
        }

        public Boolean DecimalOn
        {
            get
            {
                return _DecimalOn;
            }
            set
            {
                _DecimalOn = value;                
            }
        }

        #endregion
        #region Private Methods

        private void UpdateDisplay()
        {
            TurnAllLedsOff();

            SetDecimal();

            switch (_Value.ToLower())
            {
                case "0":
                    Top.Visibility = Visibility.Visible;
                    Bottom.Visibility = Visibility.Visible;
                    TopLeft.Visibility = Visibility.Visible;
                    TopRight.Visibility = Visibility.Visible;
                    BottomLeft.Visibility = Visibility.Visible;
                    BottomRight.Visibility = Visibility.Visible;
                    break;
                case "1":
                    TopRight.Visibility = Visibility.Visible;
                    BottomRight.Visibility = Visibility.Visible;
                    break;
                case "2":
                    Top.Visibility = Visibility.Visible;
                    Bottom.Visibility = Visibility.Visible;
                    Middle.Visibility = Visibility.Visible;
                    TopRight.Visibility = Visibility.Visible;
                    BottomLeft.Visibility = Visibility.Visible;
                    break;

                case "3":
                    Top.Visibility = Visibility.Visible;
                    Bottom.Visibility = Visibility.Visible;
                    Middle.Visibility = Visibility.Visible;
                    TopRight.Visibility = Visibility.Visible;
                    BottomRight.Visibility = Visibility.Visible;

                    break;

                case "4":
                    Middle.Visibility = Visibility.Visible;
                    TopLeft.Visibility = Visibility.Visible;
                    TopRight.Visibility = Visibility.Visible;
                    BottomRight.Visibility = Visibility.Visible;

                    break;

                case "5":
                    Top.Visibility = Visibility.Visible;
                    Bottom.Visibility = Visibility.Visible;
                    Middle.Visibility = Visibility.Visible;
                    TopLeft.Visibility = Visibility.Visible;
                    BottomRight.Visibility = Visibility.Visible;

                    break;

                case "6":
                    Top.Visibility = Visibility.Visible;
                    Bottom.Visibility = Visibility.Visible;
                    Middle.Visibility = Visibility.Visible;
                    TopLeft.Visibility = Visibility.Visible;
                    BottomLeft.Visibility = Visibility.Visible;
                    BottomRight.Visibility = Visibility.Visible;

                    break;

                case "7":
                    Top.Visibility = Visibility.Visible;
                    TopRight.Visibility = Visibility.Visible;
                    BottomRight.Visibility = Visibility.Visible;

                    break;

                case "8":
                    Top.Visibility = Visibility.Visible;
                    Bottom.Visibility = Visibility.Visible;
                    Middle.Visibility = Visibility.Visible;
                    TopLeft.Visibility = Visibility.Visible;
                    TopRight.Visibility = Visibility.Visible;
                    BottomLeft.Visibility = Visibility.Visible;
                    BottomRight.Visibility = Visibility.Visible;

                    break;

                case "9":
                    Top.Visibility = Visibility.Visible;
                    Bottom.Visibility = Visibility.Visible;
                    Middle.Visibility = Visibility.Visible;
                    TopLeft.Visibility = Visibility.Visible;
                    TopRight.Visibility = Visibility.Visible;
                    BottomRight.Visibility = Visibility.Visible;

                    break;

                case "a":
                    Top.Visibility = Visibility.Visible;
                    Middle.Visibility = Visibility.Visible;
                    TopLeft.Visibility = Visibility.Visible;
                    BottomLeft.Visibility = Visibility.Visible;
                    TopRight.Visibility = Visibility.Visible;
                    BottomRight.Visibility = Visibility.Visible;

                    break;

                case "b":
                    Top.Visibility = Visibility.Visible;
                    Middle.Visibility = Visibility.Visible;
                    TopLeft.Visibility = Visibility.Visible;
                    BottomLeft.Visibility = Visibility.Visible;

                    break;

                case "c":
                    Top.Visibility = Visibility.Visible;
                    TopLeft.Visibility = Visibility.Visible;
                    BottomLeft.Visibility = Visibility.Visible;
                    Bottom.Visibility = Visibility.Visible;

                    break;

                case "d":
                    Top.Visibility = Visibility.Visible;
                    Middle.Visibility = Visibility.Visible;
                    TopLeft.Visibility = Visibility.Visible;
                    BottomLeft.Visibility = Visibility.Visible;

                    break;

                case "e":
                    Top.Visibility = Visibility.Visible;
                    Middle.Visibility = Visibility.Visible;
                    TopLeft.Visibility = Visibility.Visible;
                    BottomLeft.Visibility = Visibility.Visible;
                    Bottom.Visibility = Visibility.Visible;

                    break;

                // I figured I would include my initials ;)
                case "f":
                    Top.Visibility = Visibility.Visible;
                    Middle.Visibility = Visibility.Visible;
                    TopLeft.Visibility = Visibility.Visible;
                    BottomLeft.Visibility = Visibility.Visible;

                    break;

                case "g":
                    Top.Visibility = Visibility.Visible;
                    Middle.Visibility = Visibility.Visible;
                    TopLeft.Visibility = Visibility.Visible;
                    BottomLeft.Visibility = Visibility.Visible;
                    Bottom.Visibility = Visibility.Visible;
                    BottomRight.Visibility = Visibility.Visible;

                    break;

                case "h":
                    Middle.Visibility = Visibility.Visible;
                    TopLeft.Visibility = Visibility.Visible;
                    BottomLeft.Visibility = Visibility.Visible;
                    TopRight.Visibility = Visibility.Visible;
                    BottomRight.Visibility = Visibility.Visible;

                    break;

                case "i":
                    Top.Visibility = Visibility.Visible;
                    Middle.Visibility = Visibility.Visible;
                    TopLeft.Visibility = Visibility.Visible;
                    BottomLeft.Visibility = Visibility.Visible;

                    break;

                case "j":
                    Top.Visibility = Visibility.Visible;
                    Middle.Visibility = Visibility.Visible;
                    TopLeft.Visibility = Visibility.Visible;
                    BottomLeft.Visibility = Visibility.Visible;

                    break;

                case "k":
                    Top.Visibility = Visibility.Visible;
                    Middle.Visibility = Visibility.Visible;
                    TopLeft.Visibility = Visibility.Visible;
                    BottomLeft.Visibility = Visibility.Visible;

                    break;

                case "l":
                    Bottom.Visibility = Visibility.Visible;
                    TopLeft.Visibility = Visibility.Visible;
                    BottomLeft.Visibility = Visibility.Visible;

                    break;

                case "m":
                    Top.Visibility = Visibility.Visible;
                    Middle.Visibility = Visibility.Visible;
                    TopLeft.Visibility = Visibility.Visible;
                    BottomLeft.Visibility = Visibility.Visible;

                    break;

                case "n":
                    Top.Visibility = Visibility.Visible;
                    Middle.Visibility = Visibility.Visible;
                    TopLeft.Visibility = Visibility.Visible;
                    BottomLeft.Visibility = Visibility.Visible;

                    break;

                case "o":
                    Top.Visibility = Visibility.Visible;
                    TopLeft.Visibility = Visibility.Visible;
                    BottomLeft.Visibility = Visibility.Visible;
                    TopRight.Visibility = Visibility.Visible;
                    BottomRight.Visibility = Visibility.Visible;

                    break;

                case "p":
                    Top.Visibility = Visibility.Visible;
                    Middle.Visibility = Visibility.Visible;
                    TopLeft.Visibility = Visibility.Visible;
                    BottomLeft.Visibility = Visibility.Visible;
                    TopRight.Visibility = Visibility.Visible;

                    break;

                case "q":
                    Top.Visibility = Visibility.Visible;
                    Middle.Visibility = Visibility.Visible;
                    TopLeft.Visibility = Visibility.Visible;
                    BottomLeft.Visibility = Visibility.Visible;

                    break;

                case "r":
                    Top.Visibility = Visibility.Visible;
                    Middle.Visibility = Visibility.Visible;
                    TopLeft.Visibility = Visibility.Visible;
                    BottomLeft.Visibility = Visibility.Visible;

                    break;

                case "s":
                    Top.Visibility = Visibility.Visible;
                    Middle.Visibility = Visibility.Visible;
                    TopLeft.Visibility = Visibility.Visible;
                    BottomRight.Visibility = Visibility.Visible;
                    Bottom.Visibility = Visibility.Visible;

                    break;

                case "t":
                    Top.Visibility = Visibility.Visible;
                    Middle.Visibility = Visibility.Visible;
                    TopLeft.Visibility = Visibility.Visible;
                    BottomLeft.Visibility = Visibility.Visible;

                    break;

                case "u":
                    TopLeft.Visibility = Visibility.Visible;
                    BottomLeft.Visibility = Visibility.Visible;
                    Bottom.Visibility = Visibility.Visible;
                    TopRight.Visibility = Visibility.Visible;
                    BottomRight.Visibility = Visibility.Visible;

                    break;

                case "v":
                    Top.Visibility = Visibility.Visible;
                    Middle.Visibility = Visibility.Visible;
                    TopLeft.Visibility = Visibility.Visible;
                    BottomLeft.Visibility = Visibility.Visible;

                    break;

                case "w":
                    Top.Visibility = Visibility.Visible;
                    Middle.Visibility = Visibility.Visible;
                    TopLeft.Visibility = Visibility.Visible;
                    BottomLeft.Visibility = Visibility.Visible;

                    break;

                case "x":
                    Top.Visibility = Visibility.Visible;
                    Middle.Visibility = Visibility.Visible;
                    TopLeft.Visibility = Visibility.Visible;
                    BottomLeft.Visibility = Visibility.Visible;

                    break;

                case "y":
                    Top.Visibility = Visibility.Visible;
                    Middle.Visibility = Visibility.Visible;
                    TopLeft.Visibility = Visibility.Visible;
                    BottomLeft.Visibility = Visibility.Visible;

                    break;

                case "z":
                    Top.Visibility = Visibility.Visible;
                    Middle.Visibility = Visibility.Visible;
                    TopLeft.Visibility = Visibility.Visible;
                    BottomLeft.Visibility = Visibility.Visible;

                    break;

                // Show a Minus "-" for all other values
                default:
                    Middle.Visibility = Visibility.Visible;
                    break;
            }

        }

        private void TurnAllLedsOff()
        {
            Top.Visibility = Visibility.Collapsed;
            Middle.Visibility = Visibility.Collapsed;
            Bottom.Visibility = Visibility.Collapsed;

            BottomLeft.Visibility = Visibility.Collapsed;
            BottomRight.Visibility = Visibility.Collapsed;

            TopLeft.Visibility = Visibility.Collapsed;
            TopRight.Visibility = Visibility.Collapsed;

            LeadingDecimal.Visibility = Visibility.Collapsed;

        }

        private void SetDecimal()
        {
            if (_DecimalOn)
            {
                LeadingDecimal.Visibility = Visibility.Visible;
            }
            else
            {
                LeadingDecimal.Visibility = Visibility.Collapsed;
            }
        }
        #endregion
	}
}